package cn.codepandas.unifiedresponse.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 统一响应结果的的包装
 *
 * @author Amaris
 * @since 1.0.0
 */
public final class UnifiedResult<T> {

    private Integer status;
    private String code;
    private String message;
    private String tip;
    private T data;

    public UnifiedResult() {
    }

    public UnifiedResult(IResultCode iResultCode) {
        this.status = iResultCode.getStatus();
        this.code = iResultCode.getCode();
        this.message = iResultCode.getMessage();
        this.tip = iResultCode.getTip();
    }

    public UnifiedResult(IResultCode iResultCode, T data) {
        this(iResultCode);
        this.data = data;
    }

    @Override
    public String toString() {
        return "UnifiedResult{" +
                "status=" + status +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", tip='" + tip + '\'' +
                ", data=" + data +
                '}';
    }

    @JsonIgnore
    @JSONField(serialize = false)
    public Integer getStatus() {
        return status;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getTip() {
        return tip;
    }

    public T getData() {
        return data;
    }

    @JsonIgnore
    @JSONField(serialize = false)
    public Boolean isSuccess() {
        return getCode().equals(ResultCode.SUCCESS.getCode());
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public void setData(T data) {
        this.data = data;
    }
}